/*
 * @Date: 2024-09-23 14:21:07
 * @Author: Yu Weifeng weifeng.yu@gientech.com
 * @Description:
 */
import { getOptionsFromDict } from '@/apis/application/dict';

/**
 * @description: 将表格中数据列包含数据字典的列做转化，
 * @param {*} tableData 表格数据
 * @param {*} columns 表格列
 * @return {*}
 */
export function formatTableDataByDict(tableData: Array<any>, columns: Array<any>): any[] {
  const colDictMap = Object.fromEntries(columns.map((col) => [col.prop, col.dictCode]));
  return (tableData || []).map((row) => {
    Object.keys(row).forEach((col) => {
      colDictMap[col] &&
        (row[col] =
          getOptionsFromDict(colDictMap[col]).find((item: any) => item.value === row[col])?.label ||
          row[col]);
    });
    return row;
  });
}

/**
 * 计算table的序号
 */
export const tableRowOrder = (currentPage: any, pageSize: any, index: any) => {
  return (currentPage - 1) * pageSize + index + 1
}

export const formatBtnPermissionType = (routeName: any, btnType: string): string => {
  return String(routeName) + "-" + btnType
}

